
#include <boost/program_options.hpp>
namespace po = boost::program_options;

#include <vector>
#include <string>
using namespace std;

#include <core/vfs.h>
#include <sandbox/planet/PlanetApp.h>
#include <sandbox/Info.h>

// ----------------------------------------------------------------------------
// Main function, just boots the application object
// ----------------------------------------------------------------------------
#if _WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#include <OgreException.h>
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
    string module;

    try {
        po::options_description desc("Options");
        desc.add_options()
            ("help", "produce help message")
            ("module", po::value<string>(), "set compression level")
            ("gpu-program", po::value<int>(), "print supported gpu programs (ogre.log)")
            ;

        po::variables_map vm;        
        vector<string> args = po::split_winmain(strCmdLine);
        po::store(po::command_line_parser(args).options(desc).run(), vm);
        po::notify(vm);

        if (vm.count ("module")) {
            module = vm["module"].as<string>();
        }
        if (vm.count ("gpu-program")) {
            Info info;
            info.logCGUSyntaxCodes();
            exit (0);
        }
    }
    catch(exception& e) {
        cerr << "error: " << e.what() << "\n";
        return 1;
    }
    catch(...) {
        cerr << "Exception of unknown type!\n";
    }

    if (module.length() > 0) {
        try
        {
            if (module == "planet") {
                PlanetApp planetApp;
                planetApp.go ();
            }
        }
        catch( Ogre::Exception& e )
        {
            std::cerr << "An exception has occured: " << e.getFullDescription();
        }

    } else {
        std::cerr << "no module specified\n";
    }

    return 0;
}